package com.woniuxy.edubureau.controller;

import com.woniuxy.commons.entity.EchartsData;
import com.woniuxy.commons.entity.ResponseEntity;
import com.woniuxy.commons.entity.wyh.GradeInfo;
import com.woniuxy.commons.enums.TermEnum;
import com.woniuxy.commons.exception.BzeducationException;
import com.woniuxy.edubureau.service.StatisticsService;
import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: luojiwei
 * @date: 2020/7/21 11:48
 * @description: 数据统计controller
 */
@RestController
@RequestMapping("/statistic")
public class StatisticsController extends BzeducationException {
    @Autowired
    private StatisticsService statisticsService;

    //获取分数
    @GetMapping("/scores")
    public ResponseEntity<List<EchartsData<Object>>> getData(String sheetGrade, String year, Long paperTerm, String startDate, String endDate){
        List<Long> list=statisticsService.getTestPaper(paperTerm,startDate,endDate);
        ResponseEntity<List<EchartsData<Object>>> responseEntity=new ResponseEntity<>();
        responseEntity.setData(statisticsService.getEcharsData(sheetGrade,year,list));
        long endTime =  System.currentTimeMillis();
        return responseEntity;
    }

    //获取人数
    @GetMapping("/nums")
    public ResponseEntity<List<EchartsData<Object>>> getNums(String sheetGrade,String year,Long paperTerm,String startDate,String endDate){
        List<Long> list=statisticsService.getTestPaper(paperTerm,startDate,endDate);
        List<EchartsData<Object>> echartsDataList=statisticsService.getFurtherNums(sheetGrade,year,list);
        ResponseEntity<List<EchartsData<Object>>> responseEntity=new ResponseEntity<>();
        responseEntity.setData(echartsDataList);
        return responseEntity;
    }

    //获取升学率
    @GetMapping("/rate")
    public ResponseEntity<List<EchartsData<Object>>> getRate(String sheetGrade,String year,Long paperTerm,String startDate,String endDate){
        List<Long> list=statisticsService.getTestPaper(paperTerm,startDate,endDate);
        List<EchartsData<Object>> echartsDataList=statisticsService.getFurtherRate(sheetGrade,year,list);
        ResponseEntity<List<EchartsData<Object>>> responseEntity=new ResponseEntity<>();
        responseEntity.setData(echartsDataList);
        return responseEntity;
    }

    //获取学期
    @GetMapping("/terms")
    public ResponseEntity<List> getTerms(){
        ResponseEntity<List> responseEntity=new ResponseEntity<>();
        List list= Lists.newArrayList();
        for (TermEnum termEnum: TermEnum.values()) {
            Map<String,Object> map=new HashMap<>();
            map.put("index",termEnum.getIndex());
            map.put("name",termEnum.getName());
            list.add(map);
        }
        responseEntity.setData(list);
        return responseEntity;
    }

    //获取年级信息
    @GetMapping("/grades")
    public ResponseEntity<List<GradeInfo>> getGrades(){
        ResponseEntity<List<GradeInfo>> responseEntity=new ResponseEntity<>();
        responseEntity.setData(statisticsService.getGradeInfos());
        return responseEntity;
    }
}
